package com.my.study.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.my.study.commonfallback.SentinelFallback;
import com.my.study.entity.vo.ResponseVO;
import com.my.study.enums.BusinessExceptionEnum;
import com.my.study.exception.BusinessException;
import com.my.study.feign.RoleClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private RoleClient roleClient;

    @GetMapping("/query-role")
    public ResponseVO queryRole(String roleId) {
        return roleClient.queryRole(roleId);
    }

    @GetMapping("/test")
    public ResponseVO test() {
        return roleClient.test();
    }

    @GetMapping("test2")
    @SentinelResource(value = "test2", fallbackClass = {SentinelFallback.class}, fallback = "createFallback")
    public ResponseVO test2(String roleId) {
        throw BusinessException.fail(BusinessExceptionEnum.FAIL.code,"测试error");
    }
}
